var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		datalist: [],
		pagenum: 1
	},
	_onLoad:function(){
		var that = this
		that.setData({ pagenum: 1, datalist: [], $nomoreData: false });
		//$.get('my/favorite',{},function(res){
		//	that.setData(res)
		//})
		that.getDataList();
	},
	getDataList: function () {
		var that = this
		var pagenum = that.data.pagenum
		$.post('my/favorite', { pagenum: pagenum }, function (res) {
			var data = res.data
			if (pagenum == 1) {
				that.setData({ datalist: data });
				if (data.length == 0) {
					$.showEmpty('没有收藏记录');
				}
			} else {
				if (data.length == 0) {
					that.setData({ $nomoreData: true });
				} else {
					var datalist = that.data.datalist
					var newdata = datalist.concat(data)
					that.setData({ datalist: newdata });
				}
			}
			that.setData({
				sclist: data
			});
		});
	},
	onReachBottom: function () {
		if (!this.data.$dataEmpty.visible && !this.data.$nomoreData) {
			this.setData({ pagenum: this.data.pagenum + 1 })
			this.getDataList();
		}
	},
	favoritedel: function (e) {
		var that = this;
		var id = e.currentTarget.dataset.id
		$.post('my/favoritedel', { id: id }, function (data) {
			$.success(data.msg);
			setTimeout(function () {
				that.onLoad();
			}, 1000)
		});
	},
}))